<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class MemberAddress extends Model
{
    use HasFactory;

    protected $table = 'sp_member_address_2';
    protected $primaryKey = 'id';
    public $timestamps = false;

    //isdefault是否默认  1 是  2否
    const MEMBER_ADDRESS_IS_DEFAULT = 1;//是
    const MEMBER_ADDRESS_NOT_DEFAULT = 2;//否

    //is_delete是否删除  1是 2否
    const MEMBER_ADDRESS_IS_DELETE = 1;//是
    const MEMBER_ADDRESS_NOT_DELETE = 2;//否

    //归还地址列表
    protected function GetReturnAddressList($pageSize, $where)
    {
        $select = array('id', 'realname', 'mobile', 'province', 'city', 'area', 'address', 'addtime', 'status', 'isdefault', 'member_id');
        $data = $this
            ->select($select)
            ->where($where)
            ->orderBy('id', 'desc')
            ->paginate($pageSize);
        $data = $data ? $data->toArray() : array();
        return $data;
    }

    //根据id查询
    protected function GetReturnAddressById($id)
    {
        $select = array('id', 'realname', 'mobile', 'province', 'city', 'area', 'address', 'addtime', 'status', 'isdefault', 'member_id');
        $where = array(
            'id' => $id,
        );
        $data = $this
            ->select($select)
            ->where($where)
            ->first();
        $data = $data ? $data->toArray() : [];
        return $data;
    }

    //添加
    protected function addData($data)
    {
        return $data = $this->insert($data);
    }

    //根据id修改
    protected function editDataById($id, $data)
    {
        $where = array(
            'id' => $id,
        );
        return $data = $this->where($where)->update($data);
    }
}
